// 封装分类相关的代码

import {onMounted, ref} from "vue";
import {getTopCategoryAPI} from "@/apis/category.js";
import {onBeforeRouteUpdate} from "vue-router";
import {useRoute} from 'vue-router'
export function useCategory() {
  const categoryData = ref({})
  const getCategory = async (id=route.params.id) => {
    // alert(route.params.id)
    const res = await getTopCategoryAPI(id)
    categoryData.value = res.result
  }

  const route = useRoute()

  onBeforeRouteUpdate((to) => {
    // console.log(to)
    getCategory(to.params.id)
  })

  onMounted(() => {
    getCategory()
  })

  return {
    categoryData,
  }
}
